package com.cardone.platform.configuration.service;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;

import com.cardone.common.cache.Caches;
import com.cardone.common.dto.PaginationDto;
import com.cardone.platform.configuration.dto.DictionaryDto;
import com.cardone.platform.configuration.dto.DictionaryTypeDto;

/**
 * 字典服务
 *
 * @author yaohaitao
 */
public interface DictionaryService {
	/**
	 * spring bean id
	 */
	String BEAN_ID = "com.cardone.platform.configuration.service.DictionaryService";

	/**
	 * 保存:字典
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param saveDictionary
	 *          字典对象
	 *
	 * @return 字典对象
	 */
	@Deprecated
	@Transactional
	@CacheEvict(value = DictionaryService.BEAN_ID, allEntries = true)
	<P> P saveByIdOrCode(final Class<P> mappedClass, final DictionaryDto saveDictionary);

	/**
	 * 导入excel
	 *
	 * @param filename
	 *          文件名
	 * @throws IOException
	 * @throws Exception
	 */
	void importExcel(final String filename) throws Exception;

	/**
	 * 查询:字典
	 *
	 * @param typeCodeList
	 *          类别代码集合
	 * @return 字典集合Map
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_2)
	<V> Map<String, List<V>> findListMapByTypeCodeList(final Class<V> mappedClass, final List<String> typeCodeList);

	/**
	 * 读取：字典标识
	 *
	 * @param defaultId
	 *          默认值
	 * @param typeCode
	 *          类别代码
	 * @param code
	 *          代码
	 *
	 * @return 返回值
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_3)
	String readIdByTypeCodeAndCode(final String defaultId, final String typeCode, final String code);

	/**
	 * 读取：字典名称
	 *
	 * @param defaultName
	 *          默认值
	 * @param typeCode
	 *          类别代码
	 * @param code
	 *          代码
	 *
	 * @return 返回值
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_3)
	String readNameByTypeCodeAndCode(final String defaultName, final String typeCode, final String code);

	/**
	 * 读取：字典值
	 *
	 * @param 字典值
	 *          默认值
	 * @param typeCode
	 *          类别代码
	 * @param code
	 *          代码
	 *
	 * @return 返回值
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_3)
	String readValueByTypeCodeAndCode(final String defaultValue, final String typeCode, final String code);

	/**
	 * 读取：字典值
	 *
	 * @param typeCode
	 *          类别代码
	 * @param code
	 *          代码
	 *
	 * @return 返回值
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_2)
	String readValueByTypeCodeAndCode(final String typeCode, final String code);

	/**
	 * 读取：字典名称
	 *
	 * @param typeCode
	 *          类别代码
	 * @param code
	 *          代码
	 *
	 * @return 返回值
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_2)
	String readNameByTypeCodeAndCode(final String typeCode, final String code);

	/**
	 * 读取：字典标识
	 *
	 * @param typeCode
	 *          类别代码
	 * @param code
	 *          代码
	 *
	 * @return 返回值
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_2)
	String readIdByTypeCodeAndCode(final String typeCode, final String code);

	/**
	 * 查询
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param typeCode
	 *          类别代码
	 * @param code
	 *          代码
	 *
	 * @return 返回对象
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_3)
	<P> P findByTypeCodeAndCode(final Class<P> mappedClass, final String typeCode, final String code);

	/**
	 * 插入
	 *
	 * @param insertDictionary
	 *          字典对象
	 *
	 * @return 影响行数
	 */
	@Deprecated
	@Transactional
	@CacheEvict(value = DictionaryService.BEAN_ID, allEntries = true)
	int insertByCode(final DictionaryDto insertDictionary);

	/**
	 * 初始化数据字典
	 *
	 * @param initDictionaryTypeList
	 *          初始化数据字典对象集合
	 * @return
	 */
	@CacheEvict(value = DictionaryService.BEAN_ID, allEntries = true)
	void init(final List<DictionaryTypeDto> initDictionaryTypeList);

	/**
	 * 删除
	 *
	 * @param deleteDictionary
	 *          字典对象
	 *
	 * @return 影响行数
	 */
	@Deprecated
	@Transactional
	@CacheEvict(value = DictionaryService.BEAN_ID, allEntries = true)
	int deleteByIds(final DictionaryDto deleteDictionary);

	/**
	 * 更新
	 *
	 * @param updateDictionary
	 *          字典对象
	 *
	 * @return 影响行数
	 */
	@Deprecated
	@Transactional
	@CacheEvict(value = DictionaryService.BEAN_ID, allEntries = true)
	int updateByCode(final DictionaryDto updateDictionary);

	/**
	 * 查询
	 *
	 * @param readDictionary
	 *          字典对象
	 * @return 返回数据
	 */
	@Deprecated
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_1)
	Integer readByCodeNqIdForCount(final DictionaryDto readDictionary);

	/**
	 * 查询
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param findDictionary
	 *          字典对象
	 * @return 返回对象
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_2)
	<P> P findById(final Class<P> mappedClass, final DictionaryDto findDictionary);

	/**
	 * 查询
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param findDictionary
	 *          字典对象
	 *
	 * @return 返回对象
	 */
	@Deprecated
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_2)
	<P> P findByCodeOrId(final Class<P> mappedClass, final DictionaryDto findDictionary);

	/**
	 * 查询
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param findListDictionary
	 *          字典对象
	 *
	 * @return 字典对象集合
	 */
	@Deprecated
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_2)
	<P> List<P> findListByLikeCode(final Class<P> mappedClass, final DictionaryDto findListDictionary);

	/**
	 * 查询
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param typeCode
	 *          类型代码
	 *
	 * @return 字典对象集合
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_2)
	<P> List<P> findListByTypeCode(final Class<P> mappedClass, final String typeCode);

	/**
	 * 查询
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param typeId
	 *          类型标识
	 *
	 * @return 字典对象集合
	 */
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_2)
	<P> List<P> findListByTypeId(final Class<P> mappedClass, final String typeId);

	/**
	 * 分页
	 *
	 * @param mappedClass
	 *          返回类型
	 *
	 * @param paginationDictionary
	 *          字典对象
	 *
	 * @return 字典分页对象
	 */
	@Deprecated
	@Cacheable(value = DictionaryService.BEAN_ID, key = Caches.KEY_2)
	<P> PaginationDto<P> paginationByLikeCode(final Class<P> mappedClass, final DictionaryDto paginationDictionary);
}